var express = require('express');
var router = express.Router();
var sqlite3 = require('sqlite3').verbose();
var path = require('path');
/* GET users listing. */
router.get('/', function(req, res, next) {
    var aname = req.query.aname;
    var db=new sqlite3.Database(path.join(__dirname, "../db/LH.s3db"));
    try{
        sqlStr = "select * from(SELECT \
            a_suggestion.[a_no],\
            a_name, \
            commitee.[com_id],\
            com_name,\
            content,\
            a_suggestion.[time]\
          FROM \
            (a_suggestion JOIN \
            commitee on a_suggestion.[com_id] = commitee.[com_id]) join activity on a_suggestion.[a_no] = activity.[a_no]) where a_name= ?";
            sqlStr2 = "select * from a_suggestion";
            db.all(sqlStr,aname,function(err,rows){
                console.log(rows);
                if(!rows){
                    res.send('0');
                }else{
                    table={}
                    table.data=rows;
                    table.count=rows.length;
                    res.status(200).json(table);
                }
            } );
    }catch(ex){
        console.log(ex);
    }
});

module.exports = router;
